<?php

namespace App\Http\Middleware\Admin;

use Closure , Session , Cookie , Config;

use Illuminate\Http\Response;

class StoreApiAuth {

    public function handle($request , Closure $next , $gurad = null){

        $sessionKey = Cookie::get(Config::get('session.store_cookie'));

        $sessionData = Session::get($sessionKey);

        if(!isset($sessionData['userInfo']) || empty($sessionData['userInfo'])){
            return response()->json(['code' => -1000 , 'msg' => '未登录']);
        }

        $request->offsetSet('mobile' , 'true');

        $user = $sessionData['userInfo'];

        global $suuid;
        $suuid = $user['id'];

        return $next($request);
    }
}